package com.demo.chain;

import lombok.extern.slf4j.Slf4j;
import net.hasor.dataway.spi.ApiInfo;
import net.hasor.dataway.spi.PreExecuteChainSpi;
import net.hasor.utils.future.BasicFuture;
import org.apache.commons.collections4.MapUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname PreExecuteChain
 * @Description 接口执行前
 * @Date 2023/8/3 20:37
 * @Created by Leo825
 */
@Slf4j
public class PreExecuteChain implements PreExecuteChainSpi {

    public static PreExecuteChain getInstance() {
        return new PreExecuteChain();
    }

    /**
     * sql 直接前
     * @param apiInfo
     * @param basicFuture
     */
    @Override
    public void preExecute(ApiInfo apiInfo, BasicFuture<Object> basicFuture) {
        Map<String, Object> parameter = apiInfo.getParameterMap();

        // 注入用户权限参数
        parameter.putAll(MapUtils.emptyIfNull(loginUserAuthParams()));
    }


    /**
     * 获取登录用户权限参数
     * @return
     */
    private Map<String, Object> loginUserAuthParams () {
        Map<String, Object> authParams = new HashMap<>();
        // todo 注入登录用户 权限参数
        return authParams;
    }
}